| Server IP : 121.121.20.254 / Your IP : 216.73.216.202 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Program Files/LibreOffice/help/en-US/text/sbasic/shared/03/ |
Upload File : |
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<base href="../../../../../">
<noscript><meta http-equiv="refresh" content="0; URL=../../../../../en-US/noscript.html"></noscript>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SFDocuments.Document service</title>
<link rel="shortcut icon" href="media/navigation/favicon.ico">
<link type="text/css" href="normalize.css" rel="Stylesheet">
<link type="text/css" href="prism.css" rel="Stylesheet">
<link type="text/css" href="default.css" rel="Stylesheet">
<script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="languages.js"></script><script type="text/javascript" src="en-US/langnames.js"></script><script type="text/javascript" src="flexsearch.debug.js"></script><script type="text/javascript" src="prism.js"></script><script type="text/javascript" src="help2.js" defer></script><script type="text/javascript" src="a11y-toggle.js" defer></script><script type="text/javascript" src="paginathing.js" defer></script><script type="text/javascript" src="en-US/bookmarks.js" defer></script><script type="text/javascript" src="en-US/contents.js" defer></script><script type="text/javascript" src="help.js" defer></script><meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<header id="TopLeftHeader"><a class="symbol" href="en-US/text/shared/05/new_help.html"><div></div></a><a class="logo" href="en-US/text/shared/05/new_help.html"><p dir="auto">LibreOffice 24.2 Help</p></a><div class="dropdowns"><div class="modules">
<button type="button" data-a11y-toggle="modules-nav" id="modules" aria-haspopup="true" aria-expanded="false" aria-controls="modules-nav">Module</button><nav id="modules-nav" hidden=""></nav>
</div></div></header><aside class="leftside"><input id="accordion-1" name="accordion-menu" type="checkbox"><label for="accordion-1" dir="auto">Contents</label><div id="Contents" class="contents-treeview"></div></aside><div id="SearchFrame"><div id="Bookmarks">
<input id="search-bar" type="search" class="search" placeholder="Search in bookmarks for chosen module" dir="auto"><div class="nav-container" tabindex="0"><nav class="index" dir="auto"></nav></div>
</div></div>
<div id="DisplayArea" itemprop="softwareHelp" itemscope="true" itemtype="http://schema.org/SoftwareApplication">
<a name="SFDocuments-sf_document"></a>
<a name="bm_id261582733781987"></a>
<meta itemprop="keywords" content="Document service">
<a name="abstract"></a>
<h1 id="hd_id731582733781114" dir="auto">
<a name="DocumentService"></a><span class="literal">SFDocuments</span>.<span class="literal">Document</span> service</h1>
<p id="par_id381589189355849" class="paragraph" dir="auto">The <span class="literal">SFDocuments</span> library provides methods and properties to facilitate the management and manipulation of LibreOffice documents.</p>
<p id="par_id591589189364267" class="paragraph" dir="auto">Methods that are applicable for all types of documents (Text Documents, Sheets, Presentations, etc) are provided by the <span class="literal">SFDocuments.Document</span> service. Some examples are:</p>
<ul itemprop="Unordered" itemscope="true" itemtype="http://schema.org/ItemList" dir="auto">
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
<p id="par_id891589189452545" class="listitem" dir="auto">Opening, closing and saving documents</p>
</li>
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
<p id="par_id811589189463041" class="listitem" dir="auto">Accessing standard or custom properties of documents</p>
</li>
</ul>
<div class="warning">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/warning.svg" alt="warning" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id301611085807704" dir="auto">The properties, methods or arguments marked with <span class="emph">(*)</span> are <span class="emph">NOT applicable to Base documents</span>.</p></div>
</div>
<br>
<p id="par_id241589189701274" class="paragraph" dir="auto">Methods and properties that are specific to certain LibreOffice components are stored in separate services, such as <span class="literal">SFDocuments.SF_Calc</span> and <span class="literal">SFDocuments.SF_Base</span>.</p>
<p id="par_id641611090052376" class="paragraph" dir="auto">Although the Basic language does not offer inheritance between object classes, the latter services may be considered as subclasses of the <span class="literal">SFDocuments.Document</span> service. Such subclasses can invoke the properties and methods described below.</p>
<h2 id="hd_id581582885621841" dir="auto">Service invocation</h2>
<p id="par_id141609955500101" class="paragraph" dir="auto">Before using the <span class="literal">Document</span> service the <span class="literal">ScriptForge</span> library needs to be loaded or imported:</p>
<div class="embedded">
<a name="importLibs"></a>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id901528999850603" dir="auto">• Basic macros require to load <span class="literal">ScriptForge</span> library using the following statement:<br><span class="literal">GlobalScope.BasicLibraries.loadLibrary("ScriptForge")</span><br><br>• Python scripts require an import from <span class="literal">scriptforge</span> module:<br><span class="literal">from scriptforge import CreateScriptService</span>
</p></div>
</div>
<br>
</div>
<p id="par_id581611090387382" class="paragraph" dir="auto">Below are three variants of how the <span class="literal">Document</span> service can be invoked.</p>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<p id="par_id181622816732197" class="paragraph" dir="auto">Using the <span class="literal">getDocument</span> method from the <span class="literal">ScriptForge</span>.<span class="literal">UI</span> service:</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim ui As Object, oDoc As Object
Set ui = CreateScriptService("UI")
Set oDoc = ui.GetDocument("Untitled 1")
</code></pre></div>
<p id="par_id181622818236233" class="paragraph" dir="auto">Alternatively you can use the methods <span class="literal">CreateDocument</span> and <span class="literal">OpenDocument</span> from the <span class="literal">UI</span> service.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Set oDocA = ui.CreateDocument("Calc")
Set oDocB = ui.OpenDocument("C:\Documents\MyFile.odt")
</code></pre></div>
<p id="par_id691622816765571" class="paragraph" dir="auto">Using a window name if the document is already open.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim oDoc As Object
Set oDoc = CreateScriptService("SFDocuments.Document", "Untitled 1") 'Default = ActiveWindow
</code></pre></div>
<p id="par_id551658777771853" class="paragraph" dir="auto">Using the document referenced by <span class="literal">ThisComponent</span>. This is specially useful when running a macro from within the Basic IDE.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim oDoc As Object
Set oDoc = CreateScriptService("Document", ThisComponent)
</code></pre></div>
<p id="par_id821622816825012" class="paragraph" dir="auto">From a macro triggered by a document event.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Sub RunEvent(ByRef poEvent As Object)
Dim oDoc As Object
Set oDoc = CreateScriptService("SFDocuments.DocumentEvent", poEvent)
' (...)
End Sub
</code></pre></div>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id831622816562430" dir="auto">The <span class="literal">Document</span> service is closely related to the <span class="literal">UI</span> and <span class="literal">FileSystem</span> services.</p></div>
</div>
<br>
<p id="par_id891582733781994" class="paragraph" dir="auto">Except when the document was closed by program with the CloseDocument method (it is then superfluous), it is recommended to free resources after use:</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Set oDoc = oDoc.Dispose()
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
from scriptforge import CreateScriptService
ui = CreateScriptService("UI")
doc = ui.GetDocument("Untitled 1")
# (...)
doc.Dispose()
</code></pre></div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
docA = ui.CreateDocument("Calc")
docB = ui.OpenDocument("C:\Documents\MyFile.odt")
</code></pre></div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc = CreateScriptService("SFDocuments.Document", "Untitled 1")
</code></pre></div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
bas = CreateScriptService("Basic")
doc = CreateScriptService("Document", bas.ThisComponent)
</code></pre></div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
def RunEvent(event)
doc = CreateScriptService("SFDocuments.DocumentEvent", Event)
# (...)
</code></pre></div>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id71611090922315" dir="auto">The use of the prefix "<span class="literal">SFDocuments.</span>" while calling the service is optional.</p></div>
</div>
<br>
<a name="bm_id81611339709014"></a>
<meta itemprop="keywords" content="API,Duration">
<meta itemprop="keywords" content="API,XComponent">
<meta itemprop="keywords" content="API,ODatabaseDocument">
<meta itemprop="keywords" content="Document service,CustomProperties property">
<meta itemprop="keywords" content="Document service,Description property">
<meta itemprop="keywords" content="Document service,DocumentProperties property">
<meta itemprop="keywords" content="Document service,DocumentType property">
<meta itemprop="keywords" content="Document service,ExportFilters property">
<meta itemprop="keywords" content="Document service,FileSystem property">
<meta itemprop="keywords" content="Document service,ImportFilters property">
<meta itemprop="keywords" content="Document service,IsBase property">
<meta itemprop="keywords" content="Document service,IsCalc property">
<meta itemprop="keywords" content="Document service,IsDraw property">
<meta itemprop="keywords" content="Document service,IsFormDocument property">
<meta itemprop="keywords" content="Document service,IsImpress property">
<meta itemprop="keywords" content="Document service,IsMath property">
<meta itemprop="keywords" content="Document service,IsWriter property">
<meta itemprop="keywords" content="Document service,Keywords property">
<meta itemprop="keywords" content="Document service,Readonly property">
<meta itemprop="keywords" content="Document service,StyleFamilies property">
<meta itemprop="keywords" content="Document service,Subject property">
<meta itemprop="keywords" content="Document service,Title property">
<meta itemprop="keywords" content="Document service,XComponent property">
<meta itemprop="keywords" content="Document service,XDocumentSettings property">
<h2 id="hd_id351582885195476" dir="auto">Properties</h2>
<a name="properties_toc"></a>
<table border="1" class="" cellpadding="0" cellspacing="0">
<tr>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id41582885195836" class="tableheadintable" dir="auto">Name</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id31582885195372" class="tableheadintable" dir="auto">Readonly</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id31582885195238" class="tableheadintable" dir="auto">Type</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id931582885195131" class="tableheadintable" dir="auto">Description</p>
</th>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id7715828856553" class="tablecontentintable" dir="auto">CustomProperties (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id861582885655779" class="tablecontentintable" dir="auto">No</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id271582885655525" class="tablecontentintable" dir="auto">Dictionary service</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id581582885655885" class="tablecontentintable" dir="auto">Returns a <span class="literal">ScriptForge.Dictionary</span> object instance. After update, can be passed again to the property for updating the document.<br>Individual items of the dictionary may be either strings, numbers, (Basic) dates or <a target="_blank" href="https://api.libreoffice.org/docs/idl/ref/structcom_1_1sun_1_1star_1_1util_1_1Duration.html"><span class="literal">com.sun.star.util.Duration</span></a> items.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id841582886030384" class="tablecontentintable" dir="auto">Description (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id441582886030118" class="tablecontentintable" dir="auto">No</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id131582886030297" class="tablecontentintable" dir="auto">String</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id471582886030489" class="tablecontentintable" dir="auto">Gives access to the Description property of the document (also known as "Comments")</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id231582886791351" class="tablecontentintable" dir="auto">DocumentProperties (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id971582886791838" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id271582886791111" class="tablecontentintable" dir="auto">Dictionary service</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id16158288679167" class="tablecontentintable" dir="auto">Returns a <span class="literal">ScriptForge.Dictionary</span> object containing all the entries. Document statistics are included. Note that they are specific to the type of document. As an example, a Calc document includes a "CellCount" entry. Other documents do not.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id881589194571813" class="tablecontentintable" dir="auto">DocumentType</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id201589194571955" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id951589194571781" class="tablecontentintable" dir="auto">String</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id941589194571801" class="tablecontentintable" dir="auto">String value with the document type ("Base", "Calc", "Writer", etc)</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id881589194572136" class="tablecontentintable" dir="auto">ExportFilters (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id201589194571699" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id951589194571391" class="tablecontentintable" dir="auto">String array</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id941589194571327" class="tablecontentintable" dir="auto">Returns a list with the export filter names applicable to the current document as a zero-based array of strings. Filters used for both import/export are also returned.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id881589194574646" class="tablecontentintable" dir="auto">FileSystem (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id201589194571306" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id951589194571114" class="tablecontentintable" dir="auto">String</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id941589194571044" class="tablecontentintable" dir="auto">Returns a string with the URL path to the root of the virtual file system of the document. Use the <span class="literal">FileSystem</span> service to view its contents, as well as to create, open and read files stored in it.</p>
<p id="par_id941589194576584" class="tablecontentintable" dir="auto">Refer to <a target="_top" href="en-US/text/sbasic/shared/03/sf_filesystem.html#virtual_fs">this help page</a> to learn more on how to access and manipulate folders and files in the virtual file system of a LibreOffice file.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id881589194573253" class="tablecontentintable" dir="auto">ImportFilters (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id201589194571067" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id951589194571292" class="tablecontentintable" dir="auto">String array</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id941589194571922" class="tablecontentintable" dir="auto">Returns a list with the import filter names applicable to the current document as a zero-based array of strings. Filters used for both import/export are also returned.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id241589194633142" class="tablecontentintable" dir="auto">
IsBase<br>IsCalc<br>IsDraw<br>IsFormDocument<br>IsImpress<br>IsMath<br>IsWriter
</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id761589194633950" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id741589194633956" class="tablecontentintable" dir="auto">Boolean</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id611589194633853" class="tablecontentintable" dir="auto">Exactly one of these properties is <span class="literal">True</span> for a given document.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id311589194910727" class="tablecontentintable" dir="auto">Keywords (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id231589194910179" class="tablecontentintable" dir="auto">No</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id421589194910942" class="tablecontentintable" dir="auto">String</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id311589194910190" class="tablecontentintable" dir="auto">Gives access to the Keywords property of the document. Represented as a comma-separated list of keywords</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id911589638614922" class="tablecontentintable" dir="auto">Readonly (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id921589638614972" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id501589638614132" class="tablecontentintable" dir="auto">Boolean</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id801589638614518" class="tablecontentintable" dir="auto"><span class="literal">True</span> if the document is actually in read-only mode</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id921589195028191" class="tablecontentintable" dir="auto">StyleFamilies (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id201589196128733" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id551589195138724" class="tablecontentintable" dir="auto">String array</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id372699195028843" class="tablecontentintable" dir="auto">List of available style families. Applicable to all document types except Base.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id031589195028191" class="tablecontentintable" dir="auto">Subject (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id201589195028733" class="tablecontentintable" dir="auto">No</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id551589195028724" class="tablecontentintable" dir="auto">String</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id371589195028843" class="tablecontentintable" dir="auto">Gives access to the Subject property of the document.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id521589195028736" class="tablecontentintable" dir="auto">Title (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id451589195028910" class="tablecontentintable" dir="auto">No</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id31589195028773" class="tablecontentintable" dir="auto">String</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id771589195028748" class="tablecontentintable" dir="auto">Gives access to the Title property of the document.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id97158288519551" class="tablecontentintable" dir="auto">XComponent</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id221582885195686" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id371582885195525" class="tablecontentintable" dir="auto">UNO Object</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id881582885195976" class="tablecontentintable" dir="auto">The UNO object <a target="_blank" href="https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1lang_1_1XComponent.html"><span class="literal">com.sun.star.lang.XComponent</span></a> or <a target="_blank" href="https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1sdb_1_1OfficeDatabaseDocument.html"><span class="literal">com.sun.star.comp.dba.ODatabaseDocument</span></a> representing the document.</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id97158299619551" class="tablecontentintable" dir="auto">XDocumentSettings (*)</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id232682885195686" class="tablecontentintable" dir="auto">Yes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id371693885195525" class="tablecontentintable" dir="auto">UNO Object</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id881582885205976" class="tablecontentintable" dir="auto">A <span class="literal">com.sun.star.XXX.DocumentSettings</span> UNO object - where XXX is sheet, text, drawing or presentation - that gives access to UNO internal properties, that are specific to the document's type.</p>
</td>
</tr>
</table>
<br>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<p id="par_id861611146581334" class="paragraph" dir="auto">The example below prints all the properties of a document. Note that the <span class="literal">oDoc</span> object returned by the <span class="literal">UI.OpenDocument</span> method is a <span class="literal">SFDocuments.Document</span> object.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim ui as Variant : Set ui = CreateScriptService("UI")
Dim oDoc as Object
Set oDoc = ui.OpenDocument("C:\Documents\MyFile.ods")
Dim propDict as Object
Set propDict = oDoc.DocumentProperties
Dim keys as Variant : propKeys = propDict.Keys
Dim k as String, strProp as String
For Each k In propKeys
strProp = strProp & k & ": " & propDict.Item(k) & CHR$(10)
Next k
MsgBox strProp
oDoc.CloseDocument()
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<p id="par_id571622826920742" class="paragraph" dir="auto">To access document properties in a Python script the user needs to directly access them using their names, as shown below:</p>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc = ui.GetDocument(r"C:\Documents\MyFile.ods")
msg = doc.Title + '\n' + doc.Description + '\n' + doc.Keywords
bas = CreateScriptService("Basic")
bas.MsgBox(msg)
doc.CloseDocument()
</code></pre></div>
<a name="methods_toc"></a>
<table border="1" class="" cellpadding="0" cellspacing="0">
<tr>
<th rowspan="" colspan="3" class="tableheadcell" dir="auto"><p id="par_id651606319520519" class="tableheadintable" dir="auto">List of Methods in the Document Service</p></th>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id761611086279902" class="tablecontentintable" dir="auto">
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#Activate">Activate</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#CloseDocument">CloseDocument</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#CreateMenu">CreateMenu</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#CreateMenu">DeleteStyles</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#Echo">Echo</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#ExportAsPDF">ExportAsPDF</a><br>
</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id141611086279902" class="tablecontentintable" dir="auto">
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#ExportAsPDF">ImportStylesFromFile</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#PrintOut">PrintOut</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#RemoveMenu">RemoveMenu</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#RunCommand">RunCommand</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#Save">Save</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#SaveAs">SaveAs</a><br>
</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id761611086279903" class="tablecontentintable" dir="auto">
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#SaveCopyAs">SaveCopyAs</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#SetPrinter">SetPrinter</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#SetPrinter">Style</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#Toolbars">Toolbars</a><br>
<a target="_top" href="en-US/text/sbasic/shared/03/sf_document.html#SetPrinter">XStyle</a><br><br>
</p>
</td>
</tr>
</table>
<br>
<a name="Activate"></a>
<a name="bm_id92158919969883"></a>
<meta itemprop="keywords" content="Document service,Activate">
<h2 id="hd_id201589199698251" dir="auto">Activate</h2>
<p id="par_id93158919969864" class="paragraph" dir="auto">Returns <span class="literal">True</span> if the document could be activated. Otherwise, there is no change in the actual user interface. It is equivalent to the <span class="literal">Activate</span> method of the <span class="literal">UI</span> service.</p>
<p id="par_id421611148353046" class="paragraph" dir="auto">This method is useful when one needs to give focus for a document that is minimized or hidden.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id181622827609276" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.Activate(): bool</span>
</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<p id="par_id601611148017930" class="paragraph" dir="auto">The example below considers that the file "My_File.ods" is already open but not active.</p>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim oDoc As Object
Set oDoc = CreateScriptService("Document", "MyFile.ods")
oDoc.Activate()
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc = CreateScriptService("Document", "MyFile.ods")
doc.Activate()
</code></pre></div>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id601611148080503" dir="auto">Keep in mind that you can invoke the <span class="literal">Document</span> service by passing to <span class="literal">CreateScriptService</span> either "Document" or "SFDocuments.Document"</p></div>
</div>
<br>
<a name="CloseDocument"></a>
<a name="bm_id721589200121249"></a>
<meta itemprop="keywords" content="Document service,CloseDocument">
<h2 id="hd_id261589200121415" dir="auto">CloseDocument</h2>
<p id="par_id651589200121138" class="paragraph" dir="auto">Closes the document. If the document is already closed, regardless of how the document was closed, this method has no effect and returns <span class="literal">False</span>.</p>
<p id="par_id341611149562894" class="paragraph" dir="auto">The method will also return <span class="literal">False</span> if the user declines to close it.</p>
<p id="par_id981611149616934" class="paragraph" dir="auto">Returns <span class="literal">True</span> if the document was successfully closed.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id1001622887222169" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.CloseDocument(saveask: bool = True): bool</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id361589200121646" class="paragraph" dir="auto"><span class="emph">saveask</span> : If <span class="literal">True</span> (default), the user is invited to confirm if the changes should be written on disk. This argument is ignored if the document was not modified.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
If oDoc.CloseDocument(True) Then
' ...
End If
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
if doc.CloseDocument(True):
# ...
</code></pre></div>
<a name="CreateMenu"></a>
<a name="bm_id721589200120958"></a>
<meta itemprop="keywords" content="Document service,CreateMenu">
<h2 id="hd_id261589200121339" dir="auto">CreateMenu</h2>
<p id="par_id651589200121080" class="paragraph" dir="auto">Creates a new menu entry in the menubar of a given document window.</p>
<p id="par_id981611149616155" class="paragraph" dir="auto">This method returns an instance of the <a target="_top" href="en-US/text/sbasic/shared/03/sf_menu.html"><span class="input" data-tooltip="Click on text to copy to clipboard">SFWidgets.Menu</span></a> service.</p>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id721643121487974" dir="auto">The menu created is only available during the current LibreOffice session and is not saved neither in the document nor in the global application settings. Hence closing the document window will make the menu disappear. It will only reappear when the macro that creates the menu is executed again.</p></div>
</div>
<br>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id1001622887222964" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.CreateMenu(menuheader: str, [before: any], submenuchar: str = ">"): svc</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id361589200120316" class="paragraph" dir="auto"><span class="emph">menuheader</span>: The toplevel name of the new menu.</p>
<p id="par_id361589200129686" class="paragraph" dir="auto"><span class="emph">before</span>: The name (as a string) or position (as an integer starting at 1) of an existing menu before which the new menu will be placed. If no value is defined for this argument, the menu will be created at the last position in the menubar.</p>
<p id="par_id361589200122507" class="paragraph" dir="auto"><span class="emph">submenuchar</span>: The delimiter used to create menu trees when calling methods as <span class="literal">AddItem</span> from the <span class="literal">Menu</span> service. The default value is ">".</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim oDoc as Object, oMenu as Object
Set oDoc = CreateScriptService("Document")
Set oMenu = oDoc.CreateMenu("My Menu")
With oMenu
' Add items to the menu
.AddItem("Item A")
.AddItem("Item B")
' ...
' After creating the menu, the service instance can be disposed of
.Dispose()
End With
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc = CreateScriptService("Document")
menu = doc.CreateMenu("My Menu")
menu.AddItem("Item A")
menu.AddItem("Item B")
# ...
menu.Dispose()
</code></pre></div>
<a name="menu_tip"></a>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id271643139068194" dir="auto">Refer to the <a target="_top" href="en-US/text/sbasic/shared/03/sf_menu.html"><span class="input" data-tooltip="Click on text to copy to clipboard">SFWidgets.Menu</span></a> help page to learn more about how to create/remove menus in LibreOffice document windows.</p></div>
</div>
<br>
<a name="DeleteStyles"></a>
<a name="bm_id721589200120958"></a>
<meta itemprop="keywords" content="Document service,DeleteStyles">
<h2 id="hd_id261590300232440" dir="auto">DeleteStyles</h2>
<p id="par_id652699200121080" class="paragraph" dir="auto">Suppresses a single style or an array of styles given by their names within a specific styles family. Only user-defined styles may be deleted, built-in styles are ignored. It applies to all document types except <span class="literal">Base</span> and <span class="literal">FormDocument</span>.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id1001623997222964" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.DeleteStyles(family: str, stylelist: str[1..*])</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<a name="family"></a>
<p id="par_id361580300131416" class="paragraph" dir="auto"><span class="emph">family</span>: One of the style families present in the actual document, as a case-sensitive string. Valid family names can be retrieved using <span class="literal">StyleFamilies</span> property.</p>
<p id="par_id361589211129686" class="paragraph" dir="auto"><span class="emph">stylelist</span>: A single style name as a string or an array of style names. The style names may be localized or not. The StylesList is typically the output of the execution of a <span class="literal">Styles()</span> method.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
' Removing unused paragraph styles
Const family = "ParagraphStyles"
aList = oDoc.Styles(family, used := False, userDefined := True)
oDoc.DeleteStyles(family, aList)
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
# Removing styles according to a prefix
a_list = doc.Styles('ParagraphStyles', namepattern = "Py*")
doc.Styles('ParagraphStyles', a_list)
</code></pre></div>
<a name="Echo"></a>
<a name="bm_id721985200199205"></a>
<meta itemprop="keywords" content="Document service,Echo">
<h2 id="hd_id261589202103395" dir="auto">Echo</h2>
<p id="par_id156589200192258" class="paragraph" dir="auto">Suspends user interface (UI) updates during the execution of a macro. Optionally, the mouse pointer can be changed into an hourglass while UI updates are suspended.</p>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id851688837646904" dir="auto">This method may provide some performance benefits for macros that perform numerous operations that require UI updates.</p></div>
</div>
<br>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id1001622824461169" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.Echo(echoon: bool = True, hourglass: bool = False)</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id211635436910325" class="paragraph" dir="auto"><span class="emph">echoon</span>: Specify <span class="literal">False</span> to suspend UI updates. The default value is <span class="literal">True</span>, which enables real time UI updates.</p>
<p id="par_id141635436912288" class="paragraph" dir="auto"><span class="emph">hourglass</span>: Specify <span class="literal">True</span> to change the mouse pointer to an hourglass (Default = <span class="literal">False</span>).</p>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id741689124521451" dir="auto">Moving the mouse pointer after it changed to an hourglass may cause it to switch to a different pointer depending on its new background.</p></div>
</div>
<br>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
' Suspends UI updates and change mouse pointer to an hourglass
oDoc.Echo(EchoOn := False, HourGlass := True)
' Other macro commands
' ...
' Restores UI updates and mouse pointer
oDoc.Echo()
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc.Echo(echoon = False, hourglass = True)
...
doc.Echo()
</code></pre></div>
<a name="ExportAsPDF"></a>
<a name="bm_id721985200121025"></a>
<meta itemprop="keywords" content="Document service,ExportAsPDF">
<h2 id="hd_id261589202100695" dir="auto">ExportAsPDF</h2>
<p id="par_id156589200123048" class="paragraph" dir="auto">Exports the document directly as a PDF file to the specified location. Returns <span class="literal">True</span> if the PDF file was successfully created.</p>
<p id="par_id811638276067119" class="paragraph" dir="auto">The export options can be set either manually using the <span class="menuitem">File - Export As - Export as PDF</span> dialog or by calling the methods <span class="literal">GetPDFExportOptions</span> and <span class="literal">SetPDFExportOptions</span> from the <a target="_top" href="en-US/text/sbasic/shared/03/sf_session.html">Session</a> service.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id1001622827826679" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.ExportAsPDF(filename: str, overwrite: bool = False, opt pages: str, opt password: str, opt watermark: str): bool</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id211635436910641" class="paragraph" dir="auto"><span class="emph">filename</span>: The full path and file name of the PDF to be created. It must follow the <span class="literal">SF_FileSystem.FileNaming</span> notation.</p>
<p id="par_id141635436912005" class="paragraph" dir="auto"><span class="emph">overwrite</span>: Specifies if the destination file can be overwritten (Default = <span class="literal">False</span>). An error will occur if <span class="literal">overwrite</span> is set to <span class="literal">False</span> and the destination file already exists.</p>
<p id="par_id141635436913587" class="paragraph" dir="auto"><span class="emph">pages</span><span class="emph"></span>: String specifying which pages will be exported. This argument uses the same notation as in the dialog <span class="menuitem">File - Export As - Export as PDF</span>.</p>
<p id="par_id141635436919655" class="paragraph" dir="auto"><span class="emph">password</span><span class="emph"></span>: Specifies a password to open the PDF file.</p>
<p id="par_id141635436913365" class="paragraph" dir="auto"><span class="emph">watermark</span>: Text to be used as watermark in the PDF file, which will be drawn in every page of the resulting PDF.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<p id="par_id301638234284727" class="paragraph" dir="auto">The following example exports the current document as a PDF file, defines a password and overwrites the destination file if it already exists.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
oDoc.ExportAsPDF("C:\User\Documents\myFile.pdf", Password := "1234", Overwrite := True)
</code></pre></div>
<p id="par_id311638276257020" class="paragraph" dir="auto">The code snippet below gets the current PDF export options and uses them to create the PDF file.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim exportSettings as Object, oSession as Object
oSession = CreateScriptService("Session")
exportSettings = oSession.GetPDFExportOptions()
' Sets to True the option to export comments as PDF notes
exportSettings.ReplaceItem("ExportNotes", True)
oSession.SetPDFExportOptions(exportSettings)
oDoc.ExportAsPDF("C:\User\Documents\myFile.pdf")
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc.ExportAsPDF(r"C:\User\Documents\myFile.pdf", password = "1234", overwrite = True)
</code></pre></div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
session = CreateScriptService("Session")
exportSettings = oSession.GetPDFExportOptions()
exportSettings.ReplaceItem("ExportNotes", True)
session.SetPDFExportOptions(exportSettings)
doc.ExportAsPDF(r"C:\User\Documents\myFile.pdf")
</code></pre></div>
<a name="ImportStylesFromFile"></a>
<a name="bm_id832985200121350"></a>
<meta itemprop="keywords" content="Document service,ImportStylesFromFile">
<h2 id="hd_id372589202101526" dir="auto">ImportStylesFromFile</h2>
<p id="par_id266589200121149" class="paragraph" dir="auto">This method loads all the styles belonging to one or more style families from a closed file into the actual document. The actual document must be a <span class="literal">Calc</span> or a <span class="literal">Writer</span> document.</p>
<p id="par_id11701265953648" class="paragraph" dir="auto"> Are always imported together:</p>
<ul itemprop="Unordered" itemscope="true" itemtype="http://schema.org/ItemList" dir="auto">
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
<p id="par_id221701265998649" class="listitem" dir="auto"><span class="literal">ParagraphStyles</span> and <span class="literal">CharacterStyles</span></p>
</li>
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
<p id="par_id441701265999801" class="listitem" dir="auto"><span class="literal">NumberingStyles</span> and <span class="literal">ListStyles</span></p>
</li>
</ul>
<p id="par_id091611169416945" class="paragraph" dir="auto">Returns <span class="literal">True</span> if styles were successfully imported.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id2101622827822170" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.ImportStylesFromFile(filename: str, families: str[1..*], overwrite = False): bool</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id321635436910004" class="paragraph" dir="auto"><span class="emph">filename</span>: The file from which to load the styles in the <span class="literal">FileSystem</span> notation. The file is presumed to be of the same document type as the actual document.</p>
<p id="par_id251635436912157" class="paragraph" dir="auto"><span class="emph">families</span>: One of the style families present in the actual document, as a case-sensitive string or an array of such strings. Default = all families.</p>
<p id="par_id362635436912268" class="paragraph" dir="auto"><span class="emph">overwrite</span>: When <span class="literal">True</span>, the actual styles may be overwritten. Default is <span class="literal">False</span>.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
oDoc.ImportStylesFromFile("C:\User\Documents\myFile.ods", "ParagraphStyles", True)
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc.ImportStylesFromFile('C:\User\Documents\myFile.ods', ("ParagraphStyles",), False)
</code></pre></div>
<a name="PrintOut"></a>
<a name="bm_id721985200121249"></a>
<meta itemprop="keywords" content="Document service,PrintOut">
<h2 id="hd_id261589202101415" dir="auto">PrintOut</h2>
<p id="par_id156589200121138" class="paragraph" dir="auto">This method sends the contents of the document to the default printer or to the printer defined by the <span class="literal">SetPrinter</span> method.</p>
<p id="par_id981611169416934" class="paragraph" dir="auto">Returns <span class="literal">True</span> if the document was successfully printed.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id1001622827822169" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.PrintOut(pages: str = "", copies: num = 1): bool</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id211635436910093" class="paragraph" dir="auto"><span class="emph">pages</span>: The pages to print as a string, like in the user interface. Example: "1-4;10;15-18". Default is all pages.</p>
<p id="par_id141635436912146" class="paragraph" dir="auto"><span class="emph">copies</span>: The number of copies. Default is 1.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
If oDoc.PrintOut("1-4;10;15-18", Copies := 2) Then
' ...
End If
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
if doc.PrintOut(copies=3, pages='45-88'):
# ...
</code></pre></div>
<a name="RemoveMenu"></a>
<a name="bm_id721589200129148"></a>
<meta itemprop="keywords" content="Document service,RemoveMenu">
<h2 id="hd_id261589200121147" dir="auto">RemoveMenu</h2>
<p id="par_id651589200165470" class="paragraph" dir="auto">Removes a toplevel menu from the menubar of a given document window.</p>
<p id="par_id981611149610695" class="paragraph" dir="auto">Returns <span class="literal">True</span> if the specified menu could be removed. If the specified menu does not exist, the method returns <span class="literal">False</span>.</p>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id571643121106014" dir="auto">This method can be used to remove any menu entry from the document window, including default menus. However, none of these changes in the menubar are saved to the document or to the application settings. To restore the menubar to the default settings, simply close and reopen the document window.</p></div>
</div>
<br>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id1001622887065864" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.RemoveMenu(menuheader: str): bool</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id361589200121156" class="paragraph" dir="auto"><span class="emph">menuheader</span>: The toplevel name of the menu to be removed.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim oDoc as Object
Set oDoc = CreateScriptService("Document")
oDoc.RemoveMenu("My Menu")
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc = CreateScriptService("Document")
doc.RemoveMenu("My Menu")
</code></pre></div>
<div class="embedded">
<a name="menu_tip"></a>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id271643139068194" dir="auto">Refer to the <a target="_top" href="en-US/text/sbasic/shared/03/sf_menu.html"><span class="input" data-tooltip="Click on text to copy to clipboard">SFWidgets.Menu</span></a> help page to learn more about how to create/remove menus in LibreOffice document windows.</p></div>
</div>
<br>
</div>
<a name="RunCommand"></a>
<a name="bm_id601589202413561"></a>
<meta itemprop="keywords" content="Document service,RunCommand">
<h2 id="hd_id611589202413141" dir="auto">RunCommand</h2>
<p id="par_id991589202413257" class="paragraph" dir="auto">Runs a UNO command on the document window associated with the service instance. A few typical commands are: Save, SaveAs, ExportToPDF, Undo, Copy, Paste, etc.</p>
<p id="par_id261589202778896" class="paragraph" dir="auto">The document itself does not need to be active to be able to run commands.</p>
<p id="par_id921611152932311" class="paragraph" dir="auto">Commands can be run with or without arguments. Arguments are not validated before running the command. If the command or its arguments are invalid, then nothing will happen.</p>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id31644182402479" dir="auto">For a complete list of UNO commands that can be run in LibreOffice, refer to the Wiki page <a target="_blank" href="https://wiki.documentfoundation.org/Development/DispatchCommands">Development/DispatchCommands</a>.</p></div>
</div>
<br>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id521622828226683" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.RunCommand(command: str, [args: any])</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id401589202413575" class="paragraph" dir="auto"><span class="emph">command</span>: Case-sensitive string containing the UNO command name. The inclusion of the prefix ".uno:" in the command is optional. The command itself is not checked for correctness. If nothing happens after the command call, then the command is probably wrong.</p>
<p id="par_id521644182774710" class="paragraph" dir="auto"><span class="emph">args</span>: For each argument to be passed to the command, specify a pair containing the argument name and value.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<p id="par_id721611153068137" class="paragraph" dir="auto">The following example runs the <span class="literal">SelectData</span> command in a Calc file named "MyFile.ods", which will result in the selection of the data area based on the currently selected cell. Note that this command does not require any arguments.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Set oDoc = CreateScriptService("Document", "MyFile.ods")
oDoc.RunCommand("SelectData")
</code></pre></div>
<p id="par_id371644184276886" class="paragraph" dir="auto">Below is an example that runs the UNO command <span class="literal">ReplaceAll</span> and passes values for its arguments <span class="literal">SearchString</span> and <span class="literal">ReplaceString</span>. Running this command will replace all occurrence of the string "abc" by "ABC" in the current sheet.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
' Arguments passed to the command:
' SearchString = "abc"
' ReplaceString = "ABC"
oDoc.RunCommand(".uno:ReplaceAll", "SearchString", "abc", "ReplaceString", "ABC")
</code></pre></div>
<p id="par_id41644184549167" class="paragraph" dir="auto">Note that calling the command <span class="literal">ReplaceAll</span> without arguments will open the <span class="menuitem">Find and Replace</span> dialog.</p>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc = CreateScriptService("Document", "MyFile.ods")
doc.RunCommand("SelectData")
</code></pre></div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc.RunCommand(".uno:ReplaceAll", "SearchString", "abc", "ReplaceString", "ABC")
</code></pre></div>
<p id="par_id811644243228448" class="paragraph" dir="auto">In Python it is also possible to call <span class="literal">RunCommand</span> using keyword arguments:</p>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc.RunCommand(".uno:ReplaceAll", SearchString = "abc", ReplaceString = "ABC")
</code></pre></div>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id191611153511038" dir="auto">Each LibreOffice component has its own set of commands available. One easy way to learn commands is going to <span class="emph">Tools - Customize - Keyboard</span>. When you position your mouse over a function in the <span class="emph">Function</span> list, a tooltip will appear with the corresponding UNO command.</p></div>
</div>
<br>
<a name="Save"></a>
<a name="bm_id691589202925124"></a>
<meta itemprop="keywords" content="Document service,Save">
<h2 id="hd_id3615892029256" dir="auto">Save</h2>
<p id="par_id81589202925519" class="paragraph" dir="auto">Stores the document to the file location from which it was loaded. The method is ignored if the document was not modified.</p>
<p id="par_id731611153918907" class="paragraph" dir="auto">Returns <span class="literal">False</span> if the document could not be saved. An error is raised if the file is open as read-only, or if it is a new file that has not been saved yet.</p>
<p id="par_id211589203690937" class="paragraph" dir="auto">The document itself does not need to be active to run this method.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id711622828457342" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.Save(): bool</span>
</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
If Not oDoc.Save() Then
' ...
End If
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
if not doc.Save():
# ...
</code></pre></div>
<a name="SaveAs"></a>
<a name="bm_id141589203370367"></a>
<meta itemprop="keywords" content="Document service,SaveAs">
<h2 id="hd_id161589203370594" dir="auto">SaveAs</h2>
<p id="par_id121589203370778" class="paragraph" dir="auto">Stores the document to the given file location. The new location becomes the new file name on which simple Save method calls will be applied.</p>
<p id="par_id31611154475602" class="paragraph" dir="auto">Returns <span class="literal">False</span> if the document could not be saved. An error is raised when overwriting the destination is rejected or when the destination has its read-only attribute set.</p>
<p id="par_id391589203370902" class="paragraph" dir="auto">The document itself does not need to be active to run this method.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id561622828596238" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.SaveAs(filename: str, overwrite: bool = False, password: str = '', filtername: str = '', filteroptions: str = ''): bool</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id331589203370950" class="paragraph" dir="auto"><span class="emph">filename</span>: A string containing the file name to be used. It must follow the <span class="literal">SF_FileSystem.FileNaming</span> notation.</p>
<p id="par_id631589204010142" class="paragraph" dir="auto"><span class="emph">overwrite</span>: If <span class="literal">True</span>, the destination file may be overwritten (default = <span class="literal">False</span>).</p>
<p id="par_id811589204084107" class="paragraph" dir="auto"><span class="emph">password</span> (*): A non-space string to protect the document.</p>
<p id="par_id451589204163772" class="paragraph" dir="auto"><span class="emph">filtername</span> (*): The name of a filter that should be used for saving the document. If this argument is passed, then the filter must exist.</p>
<p id="par_id981589204207800" class="paragraph" dir="auto"><span class="emph">filteroptions</span> (*): An optional string of options associated with the filter.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
oDoc.SaveAs("C:\Documents\NewCopy.odt", overwrite := True)
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc.SaveAs(r"C:\Documents\NewCopy.odt", overwrite = True)
</code></pre></div>
<a name="SaveCopyAs"></a>
<a name="bm_id71158920514765"></a>
<meta itemprop="keywords" content="Document service,SaveCopyAs">
<h2 id="hd_id811589205147824" dir="auto">SaveCopyAs</h2>
<p id="par_id911589205147502" class="paragraph" dir="auto">Stores a copy of or export the document to the given file location. The actual location is unchanged.</p>
<p id="par_id381611154800685" class="paragraph" dir="auto">Returns <span class="literal">False</span> if the document could not be saved. An error is raised when overwriting the destination is rejected or when the destination has its read-only attribute set.</p>
<p id="par_id11589205147643" class="paragraph" dir="auto">The document itself does not need to be active to run this method.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id561622828596855" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.SaveCopyAs(filename: str, overwrite: bool = False, password: str = '', filtername: str = '', filteroptions: str = ''): bool</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id301589205147697" class="paragraph" dir="auto"><span class="emph">filename</span>: A string containing the file name to be used. It must follow the <span class="literal">SF_FileSystem.FileNaming</span> notation.</p>
<p id="par_id851589205147348" class="paragraph" dir="auto"><span class="emph">overwrite</span>: If <span class="literal">True</span>, the destination file may be overwritten (default = <span class="literal">False</span>).</p>
<p id="par_id821589205147330" class="paragraph" dir="auto"><span class="emph">password</span> (*): A non-space string to protect the document.</p>
<p id="par_id67158920514729" class="paragraph" dir="auto"><span class="emph">filtername</span> (*): The name of a filter that should be used for saving the document. If this argument is passed, then the filter must exist.</p>
<p id="par_id881589205147911" class="paragraph" dir="auto"><span class="emph">filteroptions</span> (*): An optional string of options associated with the filter.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
oDoc.SaveCopyAs("C:\Documents\Copy2.odt", Overwrite := True)
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc.SaveCopyAs(r"C:\Documents\Copy2.odt", overwrite = True)
</code></pre></div>
<a name="SetPrinter"></a>
<a name="bm_id71158921504765"></a>
<meta itemprop="keywords" content="Document service,SetPrinter">
<h2 id="hd_id811589502147824" dir="auto">SetPrinter</h2>
<p id="par_id911298505147502" class="paragraph" dir="auto">Defines the printer options for the document.</p>
<p id="par_id381651114800685" class="paragraph" dir="auto">Returns <span class="literal">True</span> when successful.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id261652828596855" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.SetPrinter(opt printer: str, opt orientation: str, paperformat: str): bool</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<a name="setPrinterArgs"></a>
<p id="par_id301589205741697" class="paragraph" dir="auto"><span class="emph">printer</span>: The name of the printer queue where to print to. When absent, the default printer is set.</p>
<p id="par_id851985205147348" class="paragraph" dir="auto"><span class="emph">orientation</span>: Either <span class="literal">PORTRAIT</span> or <span class="literal">LANDSCAPE</span>. When absent, left unchanged with respect to the printer settings.</p>
<p id="par_id821985205147330" class="paragraph" dir="auto"><span class="emph">paperformat</span>: Specifies the paper format as a string value that can be either <span class="literal">A3</span>, <span class="literal">A4</span>, <span class="literal">A5</span>, <span class="literal">LETTER</span>, <span class="literal">LEGAL</span> or <span class="literal">TABLOID</span>. Left unchanged when absent.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
oDoc.SetPrinter(Orientation := "PORTRAIT")
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
doc.SetPrinter(paperformat='TABLOID')
</code></pre></div>
<a name="Styles"></a>
<a name="bm_id721589200120958"></a>
<meta itemprop="keywords" content="Document service,Styles">
<h2 id="hd_id262600300121440" dir="auto">Styles</h2>
<p id="par_id652600200121080" class="paragraph" dir="auto">Retrieves a list of styles matching an optional compound criteria, the returned array may be empty. It applies to all document types except <span class="literal">Base</span>.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id1001623997333964" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.Styles(family, opt namepattern: str, opt used: bool, opt userdefined: bool, opt parentstyle: str, opt category: str): str[0..*])</span>
</p>
<div class="embedded">
<a name="family"></a>
<p id="par_id361580300131416" class="paragraph" dir="auto"><span class="emph">family</span>: One of the style families present in the actual document, as a case-sensitive string. Valid family names can be retrieved using <span class="literal">StyleFamilies</span> property.</p>
</div>
<p id="par_id361589322129686" class="paragraph" dir="auto"><span class="emph">category</span>: A case-insensitive string: TEXT, CHAPTER, LIST, INDEX, EXTRA, HTML. For their respective meanings, refer to <a target="_blank" href="https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1style_1_1ParagraphStyleCategory.html">paragraph style category</a> API documentation.</p>
<p id="par_id921701269531603" class="paragraph" dir="auto">This argument is ignored when the Family differs from "ParagraphStyles".</p>
<p id="par_id472589322129797" class="paragraph" dir="auto"><span class="emph">namepattern</span>: A filter on the style names, as a case-sensitive string pattern. The names include the internal and localized names.</p>
<p id="par_id551701269163643" class="paragraph" dir="auto">Admitted wildcard are:</p>
<ul itemprop="Unordered" itemscope="true" itemtype="http://schema.org/ItemList" dir="auto">
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
<p id="par_id481701269193780" class="listitem" dir="auto">the "?" representing any single character.</p>
</li>
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto">
<p id="par_id821701269197990" class="listitem" dir="auto">the "*" representing zero, one, or multiple characters</p>
</li>
</ul>
<p id="par_id583589322129808" class="paragraph" dir="auto"><span class="emph">parentstyle</span>: When present, only the children of the given, localized or not, parent style name are retained.</p>
<p id="par_id694589322129919" class="paragraph" dir="auto"><span class="emph">used</span>: When <span class="literal">True</span>, the style must be used in the document, when absent the argument is ignored.</p>
<p id="par_id705589322129020" class="paragraph" dir="auto"><span class="emph">userdefined</span>: When <span class="literal">True</span>, the style must have been added by the user, either in the document or its template, when absent, the argument is ignored.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim vStyles As Variant
vStyles = oDoc.Styles("ParagraphStyles") ' All styles in the family
vStyles = oDoc.Styles("ParagraphStyles", "H*") ' Heading, Heading 1, ...
vStyles = oDoc.Styles("ParagraphStyles", Used := False, UserDefined := True) ' All user-defined styles that are not used
vStyles = oDoc.Styles("ParagraphStyles", ParentStyle := "Standard") ' All styles derived from the 'Default Paragraph Style'
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
vStyles = doc.Styles('ParagraphStyles') # All styles in the family
vStyles = doc.Styles('ParagraphStyles', 'H*') # Heading, Heading 1, ...
vStyles = doc.Styles('ParagraphStyles', Used = False, UserDefined = True) # All user-defined styles that are not used
vStyles = doc.Styles('ParagraphStyles', ParentStyle = 'Standard") # All styles derived from the "Default Paragraph Style"
</code></pre></div>
<a name="Toolbars"></a>
<a name="bm_id721580310120958"></a>
<meta itemprop="keywords" content="Document service,Toolbars">
<a name="SF_Toolbars"></a>
<h2 id="hd_id261501400121339" dir="auto">Toolbars</h2>
<p id="par_id091612259727155" class="paragraph" dir="auto">This method returns either a list of the available toolbar names in the actual document or an instance <a target="_top" href="en-US/text/sbasic/shared/03/sf_toolbar.html"><span class="input" data-tooltip="Click on text to copy to clipboard">SFWidgets.Toolbar</span></a> service.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id2111634997222964" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.Toolbars(opt ToolbarName: str): uno</span><br>
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.Toolbars(): str[0..]</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id361580321120786" class="paragraph" dir="auto"><span class="emph">ToolbarName</span>: The usual name of one of the available toolbars.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim oToolbar As Object
Set oToolbar = oDoc.Toolbars("myToolbar")
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
a_list = doc.Toolbars()
</code></pre></div>
<a name="XStyles"></a>
<a name="bm_id721589200120958"></a>
<meta itemprop="keywords" content="Document service,XStyles">
<h2 id="hd_id261590300121339" dir="auto">XStyles</h2>
<p id="par_id091612259616155" class="paragraph" dir="auto">This method returns the UNO representation of a given style for all document types except <span class="literal">Base</span>. <span class="literal">Nothing</span> is returned when the StyleName does not exist in the given Family.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<p id="par_id1001634997222964" class="paragraph" dir="auto">
<span class="input" data-tooltip="Click on text to copy to clipboard">svc.XStyles(family: str, stylename: str): uno</span>
</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<div class="embedded">
<a name="family"></a>
<p id="par_id361580300131416" class="paragraph" dir="auto"><span class="emph">family</span>: One of the style families present in the actual document, as a case-sensitive string. Valid family names can be retrieved using <span class="literal">StyleFamilies</span> property.</p>
</div>
<p id="par_id361589211120786" class="paragraph" dir="auto"><span class="emph">stylename</span>: One of the styles present in the given family, as a case-sensitive string. The <span class="literal">StyleName</span> may be localized or not.</p>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="embedded">
<a name="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">In Basic</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim oStyle As Object
Set oStyle = oDoc.XStyle("ParagraphStyle", "Heading 2")
</code></pre></div>
<div class="embedded">
<a name="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">In Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
oStyle = doc.XStyle('ParagraphStyle', 'Heading 2')
</code></pre></div>
<div class="embedded">
<a name="SF_InternalUse"></a>
<div class="warning">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/warning.svg" alt="warning" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id851506659675843" dir="auto">All <span class="literal">ScriptForge</span> Basic routines or identifiers that are prefixed with an underscore character "_" are reserved for internal use. They are not meant be used in Basic macros or Python scripts.</p></div>
</div>
<br>
</div>
<a name="relatedtopics"></a><div class="relatedtopics">
<p class="related" itemprop="mentions" dir="auto"><a name="related"></a><span class="emph">Related Topics</span>
</p>
<div class="relatedbody" itemprop="mentions">
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/shared/03/sf_dictionary.html"><span class="literal">ScriptForge</span>.<span class="literal">Dictionary</span> service</a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/shared/03/sf_ui.html"><span class="literal">ScriptForge</span>.<span class="literal">UI</span> service</a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/shared/03/sf_menu.html"><span class="literal">SFWidgets</span>.<span class="literal">Menu</span> service</a></p></div>
</div>
</div>
</div>
<div id="DonationFrame"></div>
<footer><div id="DEBUG" class="debug">
<h3 class="bug">Help content debug info:</h3>
<p dir="auto">This page is: <a href="https://opengrok.libreoffice.org/xref/help/source/text/sbasic/shared/03/sf_document.xhp" target="_blank">/text/sbasic/shared/03/sf_document.xhp</a></p>
<p dir="auto">Title is: SFDocuments.Document service</p>
<p id="bm_module" dir="auto"></p>
<p id="bm_system" dir="auto"></p>
<p id="bm_HID" dir="auto"></p>
</div></footer>
</body>
</html>